﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication1.Utils
{
    public static class HttpHelper
    {
        public static string Get(string url, string cookie, string referer)
        {
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;//创建请求对象
            request.Method = "GET";//请求方式
            request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36";
            request.Headers["Cookie"] = cookie;
            request.Referer = referer;
            using (Stream responseStream = request.GetResponse().GetResponseStream())
            {
                StreamReader sr = new StreamReader(responseStream,Encoding.GetEncoding("gbk"));
                string respBody = sr.ReadToEnd();
                return respBody;
            }
            
        }
    }
}
